#include <iostream>
#include <string>
#include "Logger.h"
#include "friend.pb.h"
#include "MprpcApplication.h"
#include "MprpcChannel.h"
#include "MprpcController.h"

int main(int argc, char **argv)
{   
    // 设置日志级别
        Logger::getInstance().SetLogLevel(Logger::DEBUG);

        // 设置日志文件最大大小（10KB）
        Logger::getInstance().SetMaxFileSize(10240);

        // 设置日志文件路径
        Logger::getInstance().SetLogPath("./CallFriendServiceLog/");

        LOGD("now now now %d", 112);
        
    MprpcApplication::Init(argc, argv);
    fixbug::FriendServiceRpc_Stub stub(new MprpcChannel());
    fixbug::GetFriendListRequest request;
    request.set_userid(123);

    fixbug::GetFriendListResponse response;
    MprpcController controller;
    stub.GetFriendList(&controller, &request, &response, nullptr);
    if (controller.Failed())
    {
        std::cout << controller.ErrorText() << std::endl;
    }
    else
    {
        if (0 == response.result().errcode())
        {
            std::cout << "rpc GetFriendList repponse success:" << std::endl;
            int size = response.friends_size();
            for (int i = 0; i < size; i++)
            {
                std::cout << "index:" << (i + 1) << " name: " << response.friends(i) << std::endl;
            }
        }
        else
        {
            std::cout << "rpc login response error : " << response.result().errmsg() << std::endl;
        }
    }
    return 0;
}
